package com.hexiang.seckill.mq;

import com.hexiang.seckill.redis.RedisService;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class MQSender {

    private static Logger log = LoggerFactory.getLogger(MQSender.class);

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    public void sendMiaoshaMessage(MiaoshaMessage mm) {
        String msg = RedisService.beanToString(mm);
        log.info("send message:{}", msg);
        SendResult sendResult = rocketMQTemplate.syncSend("seckill_order_topic_spring", MessageBuilder.withPayload(msg).build());
        log.warn("sendResult:{}", sendResult);

    }

}
